package com.geek.framework.study.event.reactive.stream;

import com.geek.framework.study.event.EventListener;
import com.geek.framework.study.reactive.quickstart.SimplePublisher;

import java.util.EventObject;

/**
 * @Author: ysq
 * @Date: 2021/9/1
 * @Description: 事件发布者
 */
public class EventPublisher {
  private final SimplePublisher<EventObject> simplePublisher;

  public EventPublisher() {
    simplePublisher = new SimplePublisher<>();
  }

  public void publish(Object event) {
    simplePublisher.publish(new EventObject(event));
  }

  public void addEventLister(EventListener listener) {
    simplePublisher.subscribe(new ListenerSubscriberAdapter(listener));
  }
}
